package com.wcar.sale.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.wcar.common.vo.Result;
import com.wcar.sale.service.FrontUserService;
import com.wcar.sale.service.StoreService;
import com.wcar.sale.service.UserService;
import com.wcar.sale.vo.QueryParam;
import com.wcar.sale.vo.Querysum;
import com.wcar.sale.vo.saleTN;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;

/**
 * @program: four-wcar-idea
 * @description:
 * @author: 张云龙
 * @create: 2024-05-24 00:00
 **/
@RestController
@RequestMapping("/sale")
public class SaleController {
	@Autowired
	private FrontUserService frontUserService;

	@Autowired
	private UserService userService;

	@Autowired
	private StoreService storeService;


	@GetMapping("/api/findUserStatic")
	public Result<saleTN> findUserStatic() {
		return frontUserService.getall();
	}



	@PostMapping("api/findIncome")
	public Result<Querysum> findIncome(@RequestBody QueryParam queryParam) {
		//获得当前时间
		DateTime date = DateUtil.date();
		String  replace = DateUtil.format(date, "yyyyMM");
		//拿到相对应的门店id,前端问题,传过来的门店名,与sql相性太差
		queryParam.setStoreName(storeService.zhaoid(queryParam.getStoreName()));
		//判断是否有时间截取想要字符串格式
		if (queryParam.getDate()!=null&&queryParam.getDate()!="") {
			DateTime parse = DateUtil.parse(queryParam.getDate());
			String string = DateUtil.offsetMonth(parse, +1).toString();
			queryParam.setDate(string);
			//有时间转换属性值
			replace = queryParam.getDate().toString().substring(0, 7).replace("-", "");
		}
		//返回前端回去
		queryParam.setDate(replace);
		return storeService.getall(queryParam);
	}


}
